"""
异常的捕获
try:
    可能发生错误的代码
except:
    如果出现异常执行的代码
"""
# 基本捕获语法
try:
    f = open("linux.txt","r",encoding="utf-8")
except:
    print("文件打开失败,文件不存在，创建文件")
    f = open("linux.txt","w",encoding="utf-8")
    f.close()
# 捕获指定的异常
try:
    print(f"{name}")
except NameError as e:
    print(f"出现了变量未定义的异常:{e}")
# 捕获多个异常
try:
    print(f"{name}")
    1/0
except (NameError,ZeroDivisionError) as e:
    print(f"出现了未定义变量名的异常 或 出现了除零的异常:{e}")
print("hello")

try:
    print({asd})
except Exception:
    print("出现异常了")
finally:
    print("无论有异常都执行")

